import { IRouteComponentProps,history } from "umi";
import styles from "./Login.less";
import { Form, Input, Button,message } from 'antd';
import {login} from "@/services/index";
const Login: React.FC<IRouteComponentProps> = () => {
    const onFinish = async (values: any) => {
        if(values.name==="jason"&&values.password==="123456"){
            let res=await login(values);
            console.log(res.data);
            message.success(`欢迎登录 <${res.data.name}>`);
            localStorage.setItem("user",JSON.stringify(res.data));
            localStorage.setItem("token",JSON.stringify(res.data.token));
            history.replace("/")
        }else{
            message.error('填写正确的用户名和密码');       
        }
    };
    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };
    return <div className={styles.login}>
        <div className={styles.login_cont}>
            <div className={styles.login_cont1}>
                <div className={styles.left}>
                    <span>登录页面</span>
                </div>
                <div className={styles.right}>
                    <h1>系统登录</h1>
                    <Form
                        labelAlign="left"
                        name="basic"
                        initialValues={{ remember: true }}
                        onFinish={onFinish}
                        onFinishFailed={onFinishFailed}
                    >
                        <Form.Item
                        labelAlign="left"
                            label="账号"
                            name="name"
                            rules={[{ required: true, message: '请正确输入你的用户名!' }]}
                        >
                            <Input />
                        </Form.Item>
                        <Form.Item
                        style={{flex:1}}
                            label="密码"
                            name="password"
                            rules={[{ required: true, message: '请正确输入你的密码!' }]}
                        >
                            <Input.Password />
                        </Form.Item>
                        <Form.Item >
                            <Button style={{width:"90%",height:"30px"}} type="primary" htmlType="submit">
                                登录
                            </Button>
                        </Form.Item>
                    </Form>
                    <div>
                        Or  <a> 立即注册</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
}


export default Login